"use strict";
/**
 * @name rmbShop
 * 购买付费商品
 */
const CATCOIN = 60100999;
const monthCardId = 80007;

/**
 * @name /
 * @param int id 商品ID
 * 购买付费商品
 */
module.exports = async function () {
    let shopID = this.get('id', 'int');
    if (!shopID) {
        return this.error('args empty');
    }

    let shopRandomItems = this.config('payShop', shopID);
    if (!shopRandomItems) {
        return this.error('config_not_exist', 'payShop', shopID);
    }

    // this.updater.daily.key("rmb." + shopID);
    // await this.updater.data();
    // let buyTimes = this.updater.daily.get("rmb." + shopID);
    // if (buyTimes >= shopRandomItems["payTimes"]) {
    //     return this.error("buyTimes_limit", shopID)
    // }

    //购买月卡
    //buy
    if (shopID == monthCardId) {
        this.updater.role.key('monthCardExpire');
        await this.updater.data();
        let monthCardExpire = this.updater.role.get('monthCardExpire');
        if ((monthCardExpire - Date.now()) >= 90 * 24 * 60 * 60 * 1000) {
            return this.error('已达月卡上限天数，无法购买月卡！');
        }
    }
    this.updater.item.add(shopRandomItems.payAward, shopRandomItems.payAward_number);
    this.updater.daily.add("rmb." + shopID, 1);
    this.updater.daily.add("todayAllMoney", shopRandomItems['shopRmb']);
    this.updater.daily.add("record.43", 1);
    this.updater.record.add(43, 1);
    return this.updater.save();
}
